package com.zhengxyou.jetpackdemo.greenDao;

import org.greenrobot.greendao.DaoException;
import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Index;
import org.greenrobot.greendao.annotation.NotNull;
import org.greenrobot.greendao.annotation.Property;
import org.greenrobot.greendao.annotation.ToOne;
import org.greenrobot.greendao.annotation.Transient;

@Entity(nameInDb = "greenDao_user")
public class GUser {
    @Id(autoincrement = true)
    private Long id;//默认就是自增的.如果不加autoincrement = true这里传null的话在插入的过程中id字段会自动增长（现在知道为什么id要为Long类型了吧！
    @Property(nameInDb = "name")
//    @NotNull
    @Index(unique = true)
    private String name;
    @Property(nameInDb = "create_at")//让你定义一个非默认的列名
    private String createdAt;
    @Property(nameInDb = "update_at")
    private String updateAt;
    @Transient//不会作为数据表中的一个字段
    private String imageHeader;
    private Long userflag;
    private long userInfo_id;
    @ToOne(joinProperty = "userInfo_id")
    private GUserInfo info;
    /**
     * Used to resolve relations
     */
    @Generated(hash = 2040040024)
    private transient DaoSession daoSession;
    /**
     * Used for active entity operations.
     */
    @Generated(hash = 151095197)
    private transient GUserDao myDao;

    @Generated(hash = 1844973319)
    public GUser(Long id, String name, String createdAt, String updateAt, Long userflag,
            long userInfo_id) {
        this.id = id;
        this.name = name;
        this.createdAt = createdAt;
        this.updateAt = updateAt;
        this.userflag = userflag;
        this.userInfo_id = userInfo_id;
    }

    @Generated(hash = 1115135266)
    public GUser() {
    }

    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCreatedAt() {
        return this.createdAt;
    }

    public void setCreatedAt(String createdAt) {
        this.createdAt = createdAt;
    }

    public String getUpdateAt() {
        return this.updateAt;
    }

    public void setUpdateAt(String updateAt) {
        this.updateAt = updateAt;
    }

    public long getUserInfo_id() {
        return this.userInfo_id;
    }

    public void setUserInfo_id(long userInfo_id) {
        this.userInfo_id = userInfo_id;
    }

    @Generated(hash = 1677168387)
    private transient Long info__resolvedKey;

    /**
     * To-one relationship, resolved on first access.
     */
    @Generated(hash = 205073386)
    public GUserInfo getInfo() {
        long __key = this.userInfo_id;
        if (info__resolvedKey == null || !info__resolvedKey.equals(__key)) {
            final DaoSession daoSession = this.daoSession;
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            GUserInfoDao targetDao = daoSession.getGUserInfoDao();
            GUserInfo infoNew = targetDao.load(__key);
            synchronized (this) {
                info = infoNew;
                info__resolvedKey = __key;
            }
        }
        return info;
    }

    /**
     * called by internal mechanisms, do not call yourself.
     */
    @Generated(hash = 1172994349)
    public void setInfo(@NotNull GUserInfo info) {
        if (info == null) {
            throw new DaoException(
                    "To-one property 'userInfo_id' has not-null constraint; cannot set to-one to null");
        }
        synchronized (this) {
            this.info = info;
            userInfo_id = info.getId();
            info__resolvedKey = userInfo_id;
        }
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#delete(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 128553479)
    public void delete() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.delete(this);
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#refresh(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 1942392019)
    public void refresh() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.refresh(this);
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#update(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 713229351)
    public void update() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.update(this);
    }

    public Long getUserflag() {
        return this.userflag;
    }

    public void setUserflag(Long userflag) {
        this.userflag = userflag;
    }

    /** called by internal mechanisms, do not call yourself. */
    @Generated(hash = 1840748773)
    public void __setDaoSession(DaoSession daoSession) {
        this.daoSession = daoSession;
        myDao = daoSession != null ? daoSession.getGUserDao() : null;
    }


}
